home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / sun / java2d / SurfaceData.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  12.0 KB  |  510 lines

  1. package sun.java2d;
  2.  
  3. import java.awt.AWTPermission;
  4. import java.awt.Color;
  5. import java.awt.GraphicsConfiguration;
  6. import java.awt.Image;
  7. import java.awt.Rectangle;
  8. import java.awt.Transparency;
  9. import java.awt.image.ColorModel;
  10. import java.awt.image.IndexColorModel;
  11. import java.awt.image.Raster;
  12. import java.security.Permission;
  13. import sun.awt.image.SurfaceManager;
  14. import sun.java2d.loops.CompositeType;
  15. import sun.java2d.loops.DrawGlyphList;
  16. import sun.java2d.loops.DrawGlyphListAA;
  17. import sun.java2d.loops.DrawGlyphListLCD;
  18. import sun.java2d.loops.DrawLine;
  19. import sun.java2d.loops.DrawPath;
  20. import sun.java2d.loops.DrawPolygons;
  21. import sun.java2d.loops.DrawRect;
  22. import sun.java2d.loops.FillPath;
  23. import sun.java2d.loops.FillRect;
  24. import sun.java2d.loops.FillSpans;
  25. import sun.java2d.loops.MaskFill;
  26. import sun.java2d.loops.RenderCache;
  27. import sun.java2d.loops.RenderLoops;
  28. import sun.java2d.loops.SurfaceType;
  29. import sun.java2d.pipe.AATextRenderer;
  30. import sun.java2d.pipe.AlphaColorPipe;
  31. import sun.java2d.pipe.AlphaPaintPipe;
  32. import sun.java2d.pipe.CompositePipe;
  33. import sun.java2d.pipe.DrawImage;
  34. import sun.java2d.pipe.DrawImagePipe;
  35. import sun.java2d.pipe.DuctusShapeRenderer;
  36. import sun.java2d.pipe.GeneralCompositePipe;
  37. import sun.java2d.pipe.LCDTextRenderer;
  38. import sun.java2d.pipe.LoopPipe;
  39. import sun.java2d.pipe.OutlineTextRenderer;
  40. import sun.java2d.pipe.PixelToShapeConverter;
  41. import sun.java2d.pipe.SolidTextRenderer;
  42. import sun.java2d.pipe.SpanClipRenderer;
  43. import sun.java2d.pipe.SpanShapeRenderer;
  44. import sun.java2d.pipe.TextPipe;
  45. import sun.java2d.pipe.TextRenderer;
  46.  
  47. public abstract class SurfaceData implements Transparency, DisposerTarget {
  48.    private long pData;
  49.    private boolean valid;
  50.    private boolean surfaceLost;
  51.    private SurfaceType surfaceType;
  52.    private ColorModel colorModel;
  53.    private boolean dirty;
  54.    private boolean needsBackup = true;
  55.    private int numCopies;
  56.    private Object disposerReferent = new Object();
  57.    protected static final LoopPipe colorPrimitives;
  58.    public static final TextPipe outlineTextRenderer;
  59.    public static final TextPipe solidTextRenderer;
  60.    public static final TextPipe aaTextRenderer;
  61.    public static final TextPipe lcdTextRenderer;
  62.    protected static final CompositePipe colorPipe;
  63.    protected static final PixelToShapeConverter colorViaShape;
  64.    protected static final TextPipe colorText;
  65.    protected static final CompositePipe clipColorPipe;
  66.    protected static final TextPipe clipColorText;
  67.    protected static final DuctusShapeRenderer AAColorShape;
  68.    protected static final PixelToShapeConverter AAColorViaShape;
  69.    protected static final DuctusShapeRenderer AAClipColorShape;
  70.    protected static final PixelToShapeConverter AAClipColorViaShape;
  71.    protected static final CompositePipe paintPipe;
  72.    protected static final SpanShapeRenderer paintShape;
  73.    protected static final PixelToShapeConverter paintViaShape;
  74.    protected static final TextPipe paintText;
  75.    protected static final CompositePipe clipPaintPipe;
  76.    protected static final TextPipe clipPaintText;
  77.    protected static final DuctusShapeRenderer AAPaintShape;
  78.    protected static final PixelToShapeConverter AAPaintViaShape;
  79.    protected static final DuctusShapeRenderer AAClipPaintShape;
  80.    protected static final PixelToShapeConverter AAClipPaintViaShape;
  81.    protected static final CompositePipe compPipe;
  82.    protected static final SpanShapeRenderer compShape;
  83.    protected static final PixelToShapeConverter compViaShape;
  84.    protected static final TextPipe compText;
  85.    protected static final CompositePipe clipCompPipe;
  86.    protected static final TextPipe clipCompText;
  87.    protected static final DuctusShapeRenderer AACompShape;
  88.    protected static final PixelToShapeConverter AACompViaShape;
  89.    protected static final DuctusShapeRenderer AAClipCompShape;
  90.    protected static final PixelToShapeConverter AAClipCompViaShape;
  91.    protected static final DrawImagePipe imagepipe;
  92.    static final int LCDLOOP_UNKNOWN = 0;
  93.    static final int LCDLOOP_FOUND = 1;
  94.    static final int LCDLOOP_NOTFOUND = 2;
  95.    int haveLCDLoop;
  96.    private static RenderCache loopcache;
  97.    static Permission compPermission;
  98.  
  99.    private static native void initIDs();
  100.  
  101.    protected SurfaceData(SurfaceType var1, ColorModel var2) {
  102.       this.colorModel = var2;
  103.       this.surfaceType = var1;
  104.       this.valid = true;
  105.    }
  106.  
  107.    protected SurfaceData() {
  108.       this.valid = true;
  109.    }
  110.  
  111.    public static SurfaceData getSourceSurfaceData(Image var0, SurfaceData var1, CompositeType var2, Color var3, boolean var4) {
  112.       SurfaceManager var5 = SurfaceManager.getManager(var0);
  113.       return var5.getSourceSurfaceData(var1, var2, var3, var4);
  114.    }
  115.  
  116.    public static SurfaceData getDestSurfaceData(Image var0) {
  117.       SurfaceManager var1 = SurfaceManager.getManager(var0);
  118.       return var1.getDestSurfaceData();
  119.    }
  120.  
  121.    public static SurfaceData restoreContents(Image var0) {
  122.       SurfaceManager var1 = SurfaceManager.getManager(var0);
  123.       return var1.restoreContents();
  124.    }
  125.  
  126.    public void markDirty() {
  127.       if (!this.dirty) {
  128.          this.setDirty(true);
  129.          this.needsBackup = true;
  130.          this.numCopies = 0;
  131.       }
  132.  
  133.    }
  134.  
  135.    private synchronized void setDirty(boolean var1) {
  136.       this.dirty = var1;
  137.       if (this.pData != 0L) {
  138.          setDirtyNative(this, var1);
  139.       }
  140.  
  141.    }
  142.  
  143.    private static native void setDirtyNative(SurfaceData var0, boolean var1);
  144.  
  145.    public void setNeedsBackup(boolean var1) {
  146.       this.needsBackup = var1;
  147.       if (var1) {
  148.          this.numCopies = 0;
  149.       } else {
  150.          this.setDirty(false);
  151.       }
  152.  
  153.    }
  154.  
  155.    public boolean needsBackup() {
  156.       return this.needsBackup;
  157.    }
  158.  
  159.    public void setSurfaceLost(boolean var1) {
  160.       this.surfaceLost = var1;
  161.    }
  162.  
  163.    public boolean isSurfaceLost() {
  164.       return this.surfaceLost;
  165.    }
  166.  
  167.    public final int getNumCopies() {
  168.       return this.numCopies;
  169.    }
  170.  
  171.    public int increaseNumCopies() {
  172.       if (this.dirty) {
  173.          this.setDirty(false);
  174.       }
  175.  
  176.       ++this.numCopies;
  177.       return this.numCopies;
  178.    }
  179.  
  180.    public final boolean isValid() {
  181.       return this.valid;
  182.    }
  183.  
  184.    public Object getDisposerReferent() {
  185.       return this.disposerReferent;
  186.    }
  187.  
  188.    public long getNativeOps() {
  189.       return this.pData;
  190.    }
  191.  
  192.    public void invalidate() {
  193.       this.valid = false;
  194.    }
  195.  
  196.    public abstract SurfaceData getReplacement();
  197.  
  198.    public boolean canRenderLCDText(SunGraphics2D var1) {
  199.       if (var1.compositeState <= 0 && var1.paintState <= 1 && var1.clipState <= 1 && var1.antialiasHint != 2) {
  200.          if (this.haveLCDLoop == 0) {
  201.             DrawGlyphListLCD var2 = DrawGlyphListLCD.locate(SurfaceType.AnyColor, CompositeType.SrcNoEa, this.getSurfaceType());
  202.             this.haveLCDLoop = var2 != null ? 1 : 2;
  203.          }
  204.  
  205.          return this.haveLCDLoop == 1;
  206.       } else {
  207.          return false;
  208.       }
  209.    }
  210.  
  211.    public void validatePipe(SunGraphics2D var1) {
  212.       var1.imagepipe = imagepipe;
  213.       if (var1.compositeState == 2) {
  214.          if (var1.paintState > 1) {
  215.             var1.drawpipe = paintViaShape;
  216.             var1.fillpipe = paintViaShape;
  217.             var1.shapepipe = paintShape;
  218.             var1.textpipe = outlineTextRenderer;
  219.          } else {
  220.             if (var1.clipState == 2) {
  221.                var1.drawpipe = colorViaShape;
  222.                var1.fillpipe = colorViaShape;
  223.                var1.textpipe = outlineTextRenderer;
  224.             } else {
  225.                if (var1.transformState >= 3) {
  226.                   var1.drawpipe = colorViaShape;
  227.                   var1.fillpipe = colorViaShape;
  228.                } else {
  229.                   if (var1.strokeState != 0) {
  230.                      var1.drawpipe = colorViaShape;
  231.                   } else {
  232.                      var1.drawpipe = colorPrimitives;
  233.                   }
  234.  
  235.                   var1.fillpipe = colorPrimitives;
  236.                }
  237.  
  238.                var1.textpipe = solidTextRenderer;
  239.             }
  240.  
  241.             var1.shapepipe = colorPrimitives;
  242.             var1.loops = this.getRenderLoops(var1);
  243.          }
  244.       } else if (var1.compositeState == 3) {
  245.          if (var1.antialiasHint == 2) {
  246.             if (var1.clipState == 2) {
  247.                var1.drawpipe = AAClipCompViaShape;
  248.                var1.fillpipe = AAClipCompViaShape;
  249.                var1.shapepipe = AAClipCompShape;
  250.                var1.textpipe = clipCompText;
  251.             } else {
  252.                var1.drawpipe = AACompViaShape;
  253.                var1.fillpipe = AACompViaShape;
  254.                var1.shapepipe = AACompShape;
  255.                var1.textpipe = compText;
  256.             }
  257.          } else {
  258.             var1.drawpipe = compViaShape;
  259.             var1.fillpipe = compViaShape;
  260.             var1.shapepipe = compShape;
  261.             if (var1.clipState == 2) {
  262.                var1.textpipe = clipCompText;
  263.             } else {
  264.                var1.textpipe = compText;
  265.             }
  266.          }
  267.       } else if (var1.antialiasHint == 2) {
  268.          var1.alphafill = this.getMaskFill(var1);
  269.          if (var1.alphafill != null) {
  270.             if (var1.clipState == 2) {
  271.                var1.drawpipe = AAClipColorViaShape;
  272.                var1.fillpipe = AAClipColorViaShape;
  273.                var1.shapepipe = AAClipColorShape;
  274.                var1.textpipe = clipColorText;
  275.             } else {
  276.                var1.drawpipe = AAColorViaShape;
  277.                var1.fillpipe = AAColorViaShape;
  278.                var1.shapepipe = AAColorShape;
  279.                var1.textpipe = colorText;
  280.             }
  281.          } else if (var1.clipState == 2) {
  282.             var1.drawpipe = AAClipPaintViaShape;
  283.             var1.fillpipe = AAClipPaintViaShape;
  284.             var1.shapepipe = AAClipPaintShape;
  285.             var1.textpipe = clipPaintText;
  286.          } else {
  287.             var1.drawpipe = AAPaintViaShape;
  288.             var1.fillpipe = AAPaintViaShape;
  289.             var1.shapepipe = AAPaintShape;
  290.             var1.textpipe = paintText;
  291.          }
  292.       } else if (var1.paintState <= 1 && var1.compositeState <= 0 && var1.clipState != 2) {
  293.          if (var1.transformState >= 3) {
  294.             var1.drawpipe = colorViaShape;
  295.             var1.fillpipe = colorViaShape;
  296.          } else {
  297.             if (var1.strokeState != 0) {
  298.                var1.drawpipe = colorViaShape;
  299.             } else {
  300.                var1.drawpipe = colorPrimitives;
  301.             }
  302.  
  303.             var1.fillpipe = colorPrimitives;
  304.          }
  305.  
  306.          switch (var1.textAntialiasHint) {
  307.             case 0:
  308.             case 1:
  309.                var1.textpipe = solidTextRenderer;
  310.                break;
  311.             case 2:
  312.                var1.textpipe = aaTextRenderer;
  313.                break;
  314.             default:
  315.                switch (var1.getFontInfo().aaHint) {
  316.                   case 2:
  317.                      var1.textpipe = aaTextRenderer;
  318.                      break;
  319.                   case 3:
  320.                   case 5:
  321.                   default:
  322.                      var1.textpipe = solidTextRenderer;
  323.                      break;
  324.                   case 4:
  325.                   case 6:
  326.                      var1.textpipe = lcdTextRenderer;
  327.                }
  328.          }
  329.  
  330.          var1.shapepipe = colorPrimitives;
  331.          var1.loops = this.getRenderLoops(var1);
  332.       } else {
  333.          var1.drawpipe = paintViaShape;
  334.          var1.fillpipe = paintViaShape;
  335.          var1.shapepipe = paintShape;
  336.          var1.alphafill = this.getMaskFill(var1);
  337.          if (var1.alphafill != null) {
  338.             if (var1.clipState == 2) {
  339.                var1.textpipe = clipColorText;
  340.             } else {
  341.                var1.textpipe = colorText;
  342.             }
  343.          } else if (var1.clipState == 2) {
  344.             var1.textpipe = clipPaintText;
  345.          } else {
  346.             var1.textpipe = paintText;
  347.          }
  348.       }
  349.  
  350.    }
  351.  
  352.    private static SurfaceType getPaintSurfaceType(SunGraphics2D var0) {
  353.       switch (var0.paintState) {
  354.          case 0:
  355.             return SurfaceType.OpaqueColor;
  356.          case 1:
  357.             return SurfaceType.AnyColor;
  358.          case 2:
  359.             if (var0.paint.getTransparency() == 1) {
  360.                return SurfaceType.OpaqueGradientPaint;
  361.             }
  362.  
  363.             return SurfaceType.GradientPaint;
  364.          case 3:
  365.             if (var0.paint.getTransparency() == 1) {
  366.                return SurfaceType.OpaqueTexturePaint;
  367.             }
  368.  
  369.             return SurfaceType.TexturePaint;
  370.          case 4:
  371.          default:
  372.             return SurfaceType.AnyPaint;
  373.       }
  374.    }
  375.  
  376.    protected MaskFill getMaskFill(SunGraphics2D var1) {
  377.       return MaskFill.getFromCache(getPaintSurfaceType(var1), var1.imageComp, this.getSurfaceType());
  378.    }
  379.  
  380.    public RenderLoops getRenderLoops(SunGraphics2D var1) {
  381.       SurfaceType var2 = getPaintSurfaceType(var1);
  382.       CompositeType var3 = var1.compositeState == 0 ? CompositeType.SrcNoEa : var1.imageComp;
  383.       SurfaceType var4 = var1.getSurfaceData().getSurfaceType();
  384.       Object var5 = loopcache.get(var2, var3, var4);
  385.       if (var5 != null) {
  386.          return (RenderLoops)var5;
  387.       } else {
  388.          RenderLoops var6 = makeRenderLoops(var2, var3, var4);
  389.          loopcache.put(var2, var3, var4, var6);
  390.          return var6;
  391.       }
  392.    }
  393.  
  394.    public static RenderLoops makeRenderLoops(SurfaceType var0, CompositeType var1, SurfaceType var2) {
  395.       RenderLoops var3 = new RenderLoops();
  396.       var3.drawLineLoop = DrawLine.locate(var0, var1, var2);
  397.       var3.fillRectLoop = FillRect.locate(var0, var1, var2);
  398.       var3.drawRectLoop = DrawRect.locate(var0, var1, var2);
  399.       var3.drawPolygonsLoop = DrawPolygons.locate(var0, var1, var2);
  400.       var3.drawPathLoop = DrawPath.locate(var0, var1, var2);
  401.       var3.fillPathLoop = FillPath.locate(var0, var1, var2);
  402.       var3.fillSpansLoop = FillSpans.locate(var0, var1, var2);
  403.       var3.drawGlyphListLoop = DrawGlyphList.locate(var0, var1, var2);
  404.       var3.drawGlyphListAALoop = DrawGlyphListAA.locate(var0, var1, var2);
  405.       var3.drawGlyphListLCDLoop = DrawGlyphListLCD.locate(var0, var1, var2);
  406.       return var3;
  407.    }
  408.  
  409.    public abstract GraphicsConfiguration getDeviceConfiguration();
  410.  
  411.    public final SurfaceType getSurfaceType() {
  412.       return this.surfaceType;
  413.    }
  414.  
  415.    public final ColorModel getColorModel() {
  416.       return this.colorModel;
  417.    }
  418.  
  419.    public int getTransparency() {
  420.       return this.getColorModel().getTransparency();
  421.    }
  422.  
  423.    public abstract Raster getRaster(int var1, int var2, int var3, int var4);
  424.  
  425.    public boolean useTightBBoxes() {
  426.       return true;
  427.    }
  428.  
  429.    public int pixelFor(int var1) {
  430.       return this.surfaceType.pixelFor(var1, this.colorModel);
  431.    }
  432.  
  433.    public int pixelFor(Color var1) {
  434.       return this.pixelFor(var1.getRGB());
  435.    }
  436.  
  437.    public int rgbFor(int var1) {
  438.       return this.surfaceType.rgbFor(var1, this.colorModel);
  439.    }
  440.  
  441.    public abstract Rectangle getBounds();
  442.  
  443.    protected void checkCustomComposite() {
  444.       SecurityManager var1 = System.getSecurityManager();
  445.       if (var1 != null) {
  446.          if (compPermission == null) {
  447.             compPermission = new AWTPermission("readDisplayPixels");
  448.          }
  449.  
  450.          var1.checkPermission(compPermission);
  451.       }
  452.  
  453.    }
  454.  
  455.    protected static native boolean isOpaqueGray(IndexColorModel var0);
  456.  
  457.    public static boolean isNull(SurfaceData var0) {
  458.       return var0 == null || var0 == NullSurfaceData.theInstance;
  459.    }
  460.  
  461.    public boolean copyArea(SunGraphics2D var1, int var2, int var3, int var4, int var5, int var6, int var7) {
  462.       return false;
  463.    }
  464.  
  465.    public void flush() {
  466.    }
  467.  
  468.    public abstract Object getDestination();
  469.  
  470.    static {
  471.       initIDs();
  472.       colorPrimitives = new LoopPipe();
  473.       outlineTextRenderer = new OutlineTextRenderer();
  474.       solidTextRenderer = new SolidTextRenderer();
  475.       aaTextRenderer = new AATextRenderer();
  476.       lcdTextRenderer = new LCDTextRenderer();
  477.       colorPipe = new AlphaColorPipe();
  478.       colorViaShape = new PixelToShapeConverter(colorPrimitives);
  479.       colorText = new TextRenderer(colorPipe);
  480.       clipColorPipe = new SpanClipRenderer(colorPipe);
  481.       clipColorText = new TextRenderer(clipColorPipe);
  482.       AAColorShape = new DuctusShapeRenderer(colorPipe);
  483.       AAColorViaShape = new PixelToShapeConverter(AAColorShape);
  484.       AAClipColorShape = new DuctusShapeRenderer(clipColorPipe);
  485.       AAClipColorViaShape = new PixelToShapeConverter(AAClipColorShape);
  486.       paintPipe = new AlphaPaintPipe();
  487.       paintShape = new SpanShapeRenderer.Composite(paintPipe);
  488.       paintViaShape = new PixelToShapeConverter(paintShape);
  489.       paintText = new TextRenderer(paintPipe);
  490.       clipPaintPipe = new SpanClipRenderer(paintPipe);
  491.       clipPaintText = new TextRenderer(clipPaintPipe);
  492.       AAPaintShape = new DuctusShapeRenderer(paintPipe);
  493.       AAPaintViaShape = new PixelToShapeConverter(AAPaintShape);
  494.       AAClipPaintShape = new DuctusShapeRenderer(clipPaintPipe);
  495.       AAClipPaintViaShape = new PixelToShapeConverter(AAClipPaintShape);
  496.       compPipe = new GeneralCompositePipe();
  497.       compShape = new SpanShapeRenderer.Composite(compPipe);
  498.       compViaShape = new PixelToShapeConverter(compShape);
  499.       compText = new TextRenderer(compPipe);
  500.       clipCompPipe = new SpanClipRenderer(compPipe);
  501.       clipCompText = new TextRenderer(clipCompPipe);
  502.       AACompShape = new DuctusShapeRenderer(compPipe);
  503.       AACompViaShape = new PixelToShapeConverter(AACompShape);
  504.       AAClipCompShape = new DuctusShapeRenderer(clipCompPipe);
  505.       AAClipCompViaShape = new PixelToShapeConverter(AAClipCompShape);
  506.       imagepipe = new DrawImage();
  507.       loopcache = new RenderCache(30);
  508.    }
  509. }
  510.